import React, { Component } from 'react';
import {
    View,
    DeviceEventEmitter,
    Keyboard,
    StyleSheet,
    Image,
    Platform,
    AppState,
    TouchableHighlight
} from "react-native"

import { StackNavigator, NavigationActions, NavigationSceneRendererProps, StackActions } from 'react-navigation';
import ScreenUtils from "../src/js/utils/ScreenUtils";
import GlobalColor from "../src/js/utils/GlobalColor";
import GlobalSize from "../src/js/utils/GlobalSize";

import UIManager, { SCENE_ENUM } from "../src/UIManager";



var stack = {};

for (let k in SCENE_ENUM) {
    let screen = SCENE_ENUM[k];
    stack[screen.id] = {
        screen: screen.c,

        navigationOptions: {
            header: screen.h,
            gesturesEnabled: false,//禁止滑动返回

        }
    }
}

const AppNavigator = StackNavigator(
    stack
    , {
        initialRouteName: 'LoginScreen',
        headerMode: 'screen'
    });

const resetMyAccountTab00 = StackActions.reset({
    index: 0,
    actions: [
        NavigationActions.navigate({routeName: 'Main',
            action: NavigationActions.navigate({ routeName: 'Main'})}),
    ]
})



const resetMyAccountTab = StackActions.reset({
    index: 0,
    actions: [
        NavigationActions.navigate({
            routeName: 'Home'
            , action: NavigationActions.navigate({ routeName: 'MyAccount', params: { edit: true } })
        }),
    ]
})


const resetMyReservationTab = StackActions.reset({
    index: 0,
    actions: [
        NavigationActions.navigate({
            routeName: 'Home',
            action: NavigationActions.navigate({ routeName: 'MyReservation', params: { edit: true } })
        }),
    ]
})
const resetReservationTab = StackActions.reset({
    index: 0,
    actions: [
        NavigationActions.navigate({
            routeName: 'Home',
            action: NavigationActions.navigate({ routeName: 'Reservation', params: { edit: true } })
        }),
    ]
})

export default class App extends Component {

    changeRoute() {

        console.log('打印数据哈啊',global.currentPageName);



        // if (global.currentPageName == "Main"){
        //     this.rootNavgator._navigation.dispatch(resetMyAccountTab00);
        // }
    }


    render() {

        return (
            <View style={{ flex: 1, backgroundColor: "yellow" }}>
                <AppNavigator
                    onNavigationStateChange={(oldState, newState) => {
                        const routes = newState.routes;
                        if (routes && routes.length > 0) {
                            const route = routes[routes.length - 1];
                            if (route) {
                                //设置当前页面名称
                                global.currentPageName = route.routeName || '';
                            }
                        }

                        const oldroutes = oldState.routes;
                        if (oldroutes && oldroutes.length > 1) {
                            const route = oldroutes[oldroutes.length - 2];
                            if (route) {
                                //设置当前页面名称
                                //为上一个路由
                                global.currentOldPageName = route.routeName || '';
                            }
                        }

                        this.changeRoute();

                    }}
                    ref={this.rootNavigatorRef.bind(this)}
                />



                {/*<TabModal goTabChildValue={this.goTabChildValue.bind(this)} showBtn={this.showBtnHideHandler.bind(this)} ref={(e) => {*/}
                    {/*this.model = e*/}
                {/*}} />*/}

                {/*{Platform.OS == "ios" ? <Animatable.View duration={1000} animation="zoomOut" ref={(e) => this.animtable = e} style={styles.animtableStyle}></Animatable.View> : undefined}*/}

                {/*{this.state.showLoading ? <LoadingView cancel={() => this.setState({ showProgress: false })} /> : undefined}*/}

            </View>
        );
    }

    rootNavigatorRef(instance) {
        this.rootNavgator = instance;
    }




    componentDidMount() {
        UIManager.init();
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1
    },
    bgViewStyle: {
        justifyContent: "center",
        alignItems: "center",
        position: "absolute",
        right: ScreenUtils.scaleSize(40),
        width: ScreenUtils.scaleSize(126),
        height: ScreenUtils.scaleSize(126),

    },
    logoStyle: {
        width: ScreenUtils.scaleSize(214),
        height: ScreenUtils.scaleSize(214),
        alignItems: 'center'
    },
    animtableStyle: {
        position: "absolute",
        top: 0,
        left: 0,
        right: 0,
        bottom: 0,
        backgroundColor: "#fff"
    },
    logoutItemStyle: {
        width: ScreenUtils.scaleSize(200),
        height: ScreenUtils.scaleSize(72),
        alignItems: 'center',
        justifyContent: 'center',
        backgroundColor: '#222222',
        borderRadius: GlobalSize.ScaleSize10,
        marginLeft: GlobalSize.ScaleSize30,
        marginRight: GlobalSize.ScaleSize30,
    },
    textStyle: {
        fontSize: ScreenUtils.setSpText(36),
        fontFamily: GlobalColor.FontFamilyLight,
        color: GlobalColor.bd9952
    },
    alertTitle: {
        marginTop: GlobalSize.ScaleSize20,
        color: GlobalColor["333333"],
        fontSize: GlobalSize.SetSpText30,
        fontFamily: GlobalSize.FontFamilyMedium
    },
    alertDetailTitle: {
        marginTop: GlobalSize.ScaleSize20,
        color: GlobalColor["333333"],
        fontSize: GlobalSize.SetSpText24,
        fontFamily: GlobalSize.FontFamilyRegular
    },
    logoutStyle: {
        width: ScreenUtils.scaleSize(550),
        height: ScreenUtils.scaleSize(72),
        flexDirection: "row",
        alignItems: 'center',
        marginTop: GlobalSize.ScaleSize40,
        justifyContent: "space-between"
    },
});

